package com.fbli.service.Impl;

import com.fbli.mapper.ConsultMapper;
import com.fbli.pojo.Consult;
import com.fbli.pojo.GoodsOrder;
import com.fbli.service.ConsultService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class ConsultServiceImpl implements ConsultService {
    @Autowired
    private ConsultMapper consultMapper;
    @Override
    public void insert(Consult consult) {
        //设置支付状态，评价状态，回复状态，0表示还未，1表示已经
        consult.setPaymentStatus(0);
        consult.setReplyStatus(0);
        consult.setEvaluateStatus(0);
        Timestamp time2 = new Timestamp(new Date().getTime());
        //设置订单时间
        consult.setConsultTime(time2);
        consultMapper.insert(consult);
    }

    @Override
    public void deleteByPrimaryKey(long[] consultIds) {
        System.out.println("deleteByPrimaryKey+service"+consultIds);
        for (long consultId:consultIds){
            consultMapper.deleteByPrimaryKey((int) consultId);
        }
    }

    @Override
    public void updateByPrimaryKey(Consult record) {
        System.out.println("1234"+record);
        Timestamp time = new Timestamp(System.currentTimeMillis());
        record.setReleaseTime(time);
        consultMapper.updateByPrimaryKey(record);
    }

    @Override
    public Consult selectByPrimaryKey(int consultId) {
        Consult consult = consultMapper.selectByPrimaryKey(consultId);
        return consult;
    }

    @Override
    public List<Consult> selectAll() {
        return consultMapper.selectAll();
    }

    @Override
    public List<Consult> selectConsult(String keyword) {
        return consultMapper.selectConsult(keyword);
    }

    @Override
    public PageInfo<Consult> selectPage(Consult consult, int pageNum, int pageSize) {
        //分页开始
        PageHelper.startPage(pageNum, pageSize);
        List<Consult> consults = consultMapper.selectCondition(consult);
        //返回分页后的结果
        PageInfo<Consult> consultsPageInfo = new PageInfo<>(consults);
        return consultsPageInfo;
    }
}
